package com.mcxx.modules.tool.controller;

import com.mcxx.modules.tool.service.GenerateGuicaiService;
import com.mcxx.modules.tool.service.GenerateJinMinService;
import com.mcxx.modules.tool.service.GenerateYinhaiService;
import com.mcxx.result.BaseResult;
import com.mcxx.service.DefaultRestService;
import com.yinhai.ta404.core.restservice.annotation.RestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;


@Slf4j
@Validated
@Api(tags="推送数据生成控制类")
@RestService({"generateData/v2"})
public class ExternalDataController extends DefaultRestService {

    @Autowired
    private GenerateYinhaiService generateYinhaiService;
    @Autowired
    private GenerateGuicaiService generateGuicaiService;
    @Autowired
    private GenerateJinMinService generateJinMinService;


    @PostMapping("yinhaiData")
    @ApiOperation(value="生成银海")
    @ApiImplicitParams({
            @ApiImplicitParam(name="areaCodes", value="地区:区县或省/市,多个逗号分隔", required = true, paramType="query",dataType= "String"),
            @ApiImplicitParam(name="months", value="年月:2021年6月-202106", required = true, paramType="query",dataType= "String"),
            @ApiImplicitParam(name="busiCode", value="业务类型110,130,500", required = true, paramType="query",dataType= "String"),
    })
    public void yinhaiData(@RequestParam(required=false) String areaCodes,
                               @RequestParam (required=false) String months,
                               @RequestParam (required=false) String busiCode) {
        log.info("开始生成报表，参数是：{},{},{}", areaCodes, months, busiCode);
        BaseResult<Boolean> result = generateYinhaiService.yinhaiData(areaCodes, months, busiCode);
        setData(result);
        log.info("完成生成报表，结果是：{}", result);
    }


    @PostMapping("guicaiData")
    @ApiOperation(value="生成规财")
    @ApiImplicitParams({
            @ApiImplicitParam(name="areaCodes", value="地区:区县或省/市,多个逗号分隔", required = true, paramType="query",dataType= "String"),
            @ApiImplicitParam(name="months", value="年月:2021年6月-202106", required = true, paramType="query",dataType= "String"),
            @ApiImplicitParam(name="guicaiType", value="综合统计表ID集合", required = true, paramType="query",dataType= "String"),
            @ApiImplicitParam(name="id", value="主表id", required = false, paramType="query",dataType= "String")
    })
    public void guicaiData(@RequestParam(required=true) String areaCodes,
                           @RequestParam (required=true) String months,
                           @RequestParam (required=true) String guicaiType,
                           @RequestParam (required=false) String id) {
        log.info("开始生成报表，参数是：{},{},{}", areaCodes, months, guicaiType);
        BaseResult<Boolean> result = generateGuicaiService.guicaiData(areaCodes, months, guicaiType, id);
        setData(result);
        log.info("完成生成报表，结果是：{}", result);
    }


    @PostMapping("jinminData")
    @ApiOperation(value="生成金民")
    @ApiImplicitParams({
            @ApiImplicitParam(name="areaCodes", value="地区:区县或省/市,多个逗号分隔", required = true, paramType="query",dataType= "String"),
            @ApiImplicitParam(name="months", value="年月:2021年6月-202106", required = true, paramType="query",dataType= "String"),
            @ApiImplicitParam(name="batchNo", value="综合统计表ID集合", required = true, paramType="query",dataType= "String")
    })
    public void jinminData(@RequestParam(required=true) String areaCodes,
                           @RequestParam (required=true) String months,
                           @RequestParam (required=true) String batchNo) {
        log.info("开始生成报表，参数是：{},{},{}", areaCodes, months, batchNo);
        BaseResult<Boolean> result = generateJinMinService.jinminData(areaCodes, months, batchNo);
        setData(result);
        log.info("完成生成报表，结果是：{}", result);
    }
}
